package dane.brown.sql.checker.service.impl;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import dane.brown.sql.checker.service.CheckPrinter;
import dane.brown.sql.checker.service.config.PrintConfigProperties;
import dane.brown.sql.checker.service.model.PrintRow;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
@Component
public class CsvPrinter implements CheckPrinter {
    @Autowired
    private PrintConfigProperties printConfigProperties;



    private List<PrintRow> rows = new ArrayList<>();
    @Override
    public void print(PrintRow row) {
        rows.add(row);
    }


    @Override
    public void flush() {
        try(ExcelWriter excelWriter = EasyExcel.write(printConfigProperties.getActualPath(), PrintRow.class)
                .build()){
            excelWriter.write(rows, EasyExcel.writerSheet("Sheet1").build());
        }

    }
}